import 'user_entity.dart';
import 'package:myapp/models/models.dart';

class CommentEntity {
  String commentId;
  DateTime createdAt;
  DateTime updatedAt;
  String body;
  MyUser author;

  CommentEntity({
    required this.commentId,
    required this.createdAt,
    required this.updatedAt,
    required this.body,
    required this.author,
  });

  Map<String, Object?> toDocument() {
    return {
      'commentId': commentId,
      'body': body,
      'createdAt': createdAt,
      'updatedAt': updatedAt,
      'author': author.toEntity().toDocument()
    };
  }
  static CommentEntity fromDocument(Map<String, dynamic> doc) {
    return CommentEntity(
      commentId: doc['commentId'],
      body: doc['body'],
      createdAt: doc['createdAt'],
      updatedAt: doc['updatedAt'],
      author: MyUser.fromEntity(MyUserEntity.fromDocument(doc['author'])),
    );
  }
}
